﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link href="~/layui-v2.6.8/layui-v2.6.8/layui/css/layui.css" rel="stylesheet" />
    <script src="~/layui-v2.6.8/layui-v2.6.8/layui/layui.js"></script>
    <script src="~/lib/jquery/dist/jquery.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
    <form class="layui-form" action="">

        <div class="layui-form-item">
            <div class="layui-input-block">
                <input type="hidden" name="logId" id="logId" lay-verify="required" lay-reqtext="ID是必填项，岂能为空？" placeholder="请输入组织ID" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">IP</label>
            <div class="layui-input-block">
                <input type="text" name="ipAddress" id="ipAddress" lay-verify="required" lay-reqtext="角色名称是必填项，岂能为空？" placeholder="请输入角色名称" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">操作人</label>
            <div class="layui-input-block">
                <input type="text" name="operationName" id="operationName" lay-verify="required" lay-reqtext="排序是必填项，岂能为空？" placeholder="请输入排序" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">日志信息</label>
            <div class="layui-input-block">
                <input type="text" name="logInfo" id="logInfo" lay-verify="required" lay-reqtext="备注是必填项，岂能为空？" placeholder="请输入备注" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">跟踪信息</label>
            <div class="layui-input-block">
                <input type="text" name="stackTrace" id="stackTrace" lay-verify="required" lay-reqtext="备注是必填项，岂能为空？" placeholder="请输入备注" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>

    <script>

        //（4） 前端：浏览器请求服务器的时候，要带上JWT
        $.ajaxSetup({
            beforeSend: function (xhr) {
                if (localStorage.getItem("token") !== null) {
                    //（4） 前端：浏览器请求服务器的时候，要带上JWT
                    xhr.setRequestHeader('Authorization', 'Bearer ' + localStorage.getItem("token"));
                }
            }
        });

        layui.use(['form', 'layedit', 'laydate'], function () {

            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate;

            //监听提交
            form.on('submit(demo1)', function (data) {
                console.log(data);
                $.ajax({
                    url: "https://localhost:44398/api/NlogAPI/Update?logId=" + data.logId,
                    type: 'post',
                    data: data.field,
                    success: function (data) {
                        console.log(data);
                        if (data > 0) {
                            layer.msg("修改成功", function () {
                                parent.location.href = "/NlogWeb/Index";
                            });
                        } else {
                            layer.msg("修改失败");
                            return;
                        }
                    }
                })
                return false;
            });

            //表单取值
            layui.$('#LAY-component-form-getval').on('click', function () {
                var data = form.val('example');
                alert(JSON.stringify(data));
            });
        });

        //文档就绪反填数据
        $(function () {

                $.ajax({
                    url: "https://localhost:44398/api/NlogAPI/Fantian?logId="+@ViewBag.ids,
                    type: "post",
                    success: function (d) {
                        $("#logId").val(@ViewBag.ids);
                        $("#ipAddress").val(d.data.ipAddress);
                        $("#operationName").val(d.data.operationName);
                        $("#logInfo").val(d.data.logInfo);
                        $("#stackTrace").val(d.data.stackTrace);
                    }
                })
            })
    </script>
</body>
</html>
